import jdk.internal.util.xml.impl.Input;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Scanner;

public class Test {
    public static void test2(int a) {
        try {
            if(a == 10) {
                throw new CloneNotSupportedException(); //受查异常，必须此时处理
            }
            System.out.println("1");
        }catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        System.out.println("1111");
    }

    //此时不算处理异常，只是声明  谁都没处理异常， 交给jvm
    public static void test22(int a) throws CloneNotSupportedException {
        if(a == 10) {
            throw new CloneNotSupportedException(); //受查异常，必须此时处理
        }
        System.out.println("11111");
    }

    public static void test3(int a) {

    }

    public static void main1(String[] args) {
        try {
            int[] array = {1,2,3,4};
            //array = null;
            System.out.println(array[10]);
        }catch (ArrayIndexOutOfBoundsException e) {
            e.printStackTrace();
            System.out.println("捕捉到数组越界异常！");
        }

        System.out.println("执行后续代码");
    }

    public static void main2(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {  //写进try()里会自动回收掉，不用关闭了
            int n = scanner.nextInt();
        }catch (InputMismatchException e) {
            e.printStackTrace();
            System.out.println("输入数据不匹配");
        }finally {   //一般用来关闭资源   建议不要在finally中return数据
            System.out.println("执行finally");
        }
    }



}
